#include "Core/AtomicCounter.h"


BEGIN_GLSX_NAMESPACE

AtomicCounter::AtomicCounter() :
	_counter(0)
{

}

AtomicCounter::AtomicCounter( ValueType initialValue ) :
	_counter(initialValue)
{

}

AtomicCounter::AtomicCounter( const AtomicCounter& counter ) :
	_counter(counter.value())
{

}

AtomicCounter::~AtomicCounter()
{

}

AtomicCounter& AtomicCounter::operator=( const AtomicCounter& counter )
{
	InterlockedExchange(&_counter, counter.value());
	return *this;
}

AtomicCounter& AtomicCounter::operator=( ValueType value )
{
	InterlockedExchange(&_counter, value);
	return *this;
}

inline AtomicCounter::operator AtomicCounter::ValueType () const
{
	return _counter;
}

inline AtomicCounter::ValueType AtomicCounter::value() const
{
	return _counter;
}

inline AtomicCounter::ValueType AtomicCounter::operator ++ () 
{
	return InterlockedIncrement(&_counter);
}

inline AtomicCounter::ValueType AtomicCounter::operator ++ (int) 
{
	ValueType result = InterlockedIncrement(&_counter);
	return --result;
}

inline AtomicCounter::ValueType AtomicCounter::operator -- () 
{
	return InterlockedDecrement(&_counter);
}

inline AtomicCounter::ValueType AtomicCounter::operator -- (int) 
{
	ValueType result = InterlockedDecrement(&_counter);
	return ++result;
}

inline bool AtomicCounter::operator ! () const
{
	return _counter == 0;
}

END_GLSX_NAMESPACE